package com.ggh.jinjilive.ui.mine.zhubo.adapter;

import android.graphics.Color;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;

import androidx.annotation.NonNull;
import androidx.databinding.DataBindingUtil;
import androidx.recyclerview.widget.RecyclerView;

import com.ggh.jinjilive.R;
import com.ggh.jinjilive.databinding.ItemZhuboStatementBinding;
import com.ggh.jinjilive.listener.AddItemOnClickListener;

import java.util.List;

public class ZhuBoStatementAdapter extends RecyclerView.Adapter<ZhuBoStatementAdapter.ItemViewHolder> {

    private int Selected = 0;
    public void setSelected(int Selected){
        this.Selected = Selected;
        notifyDataSetChanged();
    }

    private List<String> stringList;

    public void setAdd(List<String> stringList) {
        this.stringList = stringList;
        notifyDataSetChanged();
    }

    private AddItemOnClickListener addItemOnClickListener;

    public void setAddItemOnClickListener(AddItemOnClickListener addItemOnClickListener) {
        this.addItemOnClickListener = addItemOnClickListener;
    }

    @NonNull
    @Override
    public ItemViewHolder onCreateViewHolder(@NonNull ViewGroup parent, int viewType) {
        ItemZhuboStatementBinding binding = DataBindingUtil.inflate(LayoutInflater.from(parent.getContext()), R.layout.item_zhubo_statement, parent, false);
        return new ItemViewHolder(binding);
    }

    @Override
    public void onBindViewHolder(@NonNull ItemViewHolder holder, int position) {
        String liveCategory = stringList.get(position);
        if(null != liveCategory){
            holder.binding.dateText.setText(liveCategory);
            if(Selected == position){
                holder.binding.dateText.setTextColor(Color.parseColor("#FF0000"));
            }else {
                holder.binding.dateText.setTextColor(Color.parseColor("#FFFFFF"));
            }
            holder.binding.dateText.setOnClickListener(new View.OnClickListener() {
                @Override
                public void onClick(View view) {
                    if(null != addItemOnClickListener){
                        addItemOnClickListener.onSkipClicked(position,liveCategory);
                    }
                }
            });
        }
    }

    @Override
    public int getItemCount() {
        return null == stringList ? 0 : stringList.size();
    }

    public class ItemViewHolder extends RecyclerView.ViewHolder {
        ItemZhuboStatementBinding binding;

        public ItemViewHolder(@NonNull ItemZhuboStatementBinding binding) {
            super(binding.getRoot());
            this.binding = binding;
        }
    }
}
